<?php
	class Default_Model_Furniture extends Zend_Db_Table_Abstract
	{
		protected $_name = 'furniture';
		protected $_primary = 'id';
		protected $_db;
		
		public function __construct()
		{
			$this->_db = Zend_Registry::get('db');
		}
        
        public function getListItemForIndex()
        {
            $data = array(
                'id',
                'name',
                'thumbnail',
                'price',
                'sale_price',
                'create_date',
                'url',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('status = 1')
                            ->order('id DESC')
                            ->limit(6);
            $result = $this->_db->fetchAll($sql);
            return $result;
        }
        
        public function getListItem()
        {
            $data = array(
                'id',
                'name',
                'thumbnail',
                'price',
                'sale_price',
                'create_date',
                'url',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('status = 1')
                            ->order('id DESC');
            return $sql;
        }
        
        public function getItemByCategory($category_id, $limit = null)
        {
            $data = array(
                'id',
                'name',
                'thumbnail',
                'price',
                'sale_price',
                'create_date',
                'url',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('category_id = ?', $category_id)
                            ->where('status = 1')
                            ->order('id DESC');
            if($limit != null) {
                $sql = $sql->limit($limit);
                $result = $this->_db->fetchAll($sql);
                return $result;
            }
            else {
                return $sql;
            }
        }
        
        public function getItemById($id)
        {
            $data = array(
                'id',
                'name',
                'image',
                'price',
                'sale_price',
                'description',
                'category_id',
                'type',
            );
            $sql = $this->_db->select()
                             ->from($this->_name,$data)
                             ->where('id =?',$id);
            $result = $this->_db->fetchRow($sql);
            return $result;         
        }
        
        public function getItemContinue($id, $category_id)
        {
            $data = array(
                'id',
                'name',
                'thumbnail',
                'price',
                'sale_price',
                'create_date',
                'url',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('status = 1')
                            ->where('id <> ?', $id)
                            ->where('category_id = ?', $category_id)
                            ->order('id DESC')
                            ->limit(6);
            $result = $this->_db->fetchAll($sql);
            return $result;
        }
    }
